# -*- coding: utf-8 -*-
from datetime import timedelta
# from utils.operators.spark_sql_operator import SparkSqlOperator
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dwd.tab.dwd_tab_barscan_loading_base_dt import jms_dwd__dwd_tab_barscan_loading_base_dt
from jms.dwd.tab.dwd_tab_barscan_unloading_base_dt import jms_dwd__dwd_tab_barscan_unloading_base_dt
from jms.dwd.dwd_warhouse.dwd_wide_unsign_summary_waybill_dt import jms_dwd__dwd_wide_unsign_summary_waybill_dt
from jms.dwd.dwd_tmsnew_shipment_dt import jms_dwd__dwd_tmsnew_shipment_dt
from jms.dim.dim_tmsnew_vehicle  import jms_dim__dim_tmsnew_vehicle
from jms.dim.dim_tms_mainline_vehicleloading import jms_dim__dim_tms_mainline_vehicleloading
from jms.dim.dim_tmsnew_vehicle_line import jms_dim__dim_tmsnew_vehicle_line

jms_dwd__dwd_wide_tms_trunk_shipno_road_waybill_dt = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_tms_trunk_shipno_road_waybill_dt',
    task_concurrency=1,
    pool_slots=10,
    master='yarn',
    name='jms_dwd__dwd_wide_tms_trunk_shipno_road_waybill_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_wide_tms_trunk_shipno_road_waybill_dt/execute.sql',
    executor_cores=2,
    executor_memory='4G',
    email=['rongguangfan@jtexpress.com','yl_bigdata@yl-scm.com'],
    num_executors=25,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 50,  # 动态资源最大扩容 Executor 数
          #'spark.dynamicAllocation.maxExecutors': 11,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '1G',  # 堆外内存
          'spark.sql.shuffle.partitions': 600,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 20,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 20,  # 每天生成 20 个分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
)

jms_dwd__dwd_wide_tms_trunk_shipno_road_waybill_dt << [
    jms_dwd__dwd_tab_barscan_loading_base_dt,
    jms_dwd__dwd_tab_barscan_unloading_base_dt,
    jms_dwd__dwd_wide_unsign_summary_waybill_dt,
    jms_dwd__dwd_tmsnew_shipment_dt,
    jms_dim__dim_tmsnew_vehicle,
    jms_dim__dim_tms_mainline_vehicleloading,
    jms_dim__dim_tmsnew_vehicle_line
]
